define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cash/index' + location.search,
                    add_url: 'cash/add',
                    edit_url: 'cash/edit',
                    del_url: 'cash/del',
                    multi_url: 'cash/multi',
                    returnprice_url: 'cash/retprice',
                    table: 'table',
                },
                commonSearch: false,
                search: false,
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                       // {field: 'id', operate:false,title: __('Id')},
                        {field: 'order_number', title: __('Onumber')},
                        {
                            field: 'hotelname',
                            operate: false,
                            title: __('Hotelname'),
                            cellStyle: function (value, row, index, field) {
                                return {
                                    css: {
                                        "white-space": "nowrap",
                                        "text-overflow": "ellipsis",
                                        "overflow": "hidden",
                                        "max-width": "200px"
                                    }
                                }
                            }
                        },
                        {field: 'title',operate:false, title: __('Housename')},
                        {field: 'income',operate:false, title: __("Income")},
                         {field: 'all_money',operate:false,title: "支付金额"},
                         {field: 'return_money',operate:false,title: '退款金额'},
                        {field: 'use_hour',operate:false,title: "小时数"},
                        {field: 'ballprice',operate:false, title:__("bprice")},
                        {field: 'deposit',operate:false, title:__("deposit")},
                        {field: 'timing',operate:false, title:__("timing")},
                        {field: 'order_name',operate:false, title:__("order_name")},
                        {field: 'order_phone',operate:false, title:__("order_phone")},
                        {field: 'from',operate:false, title:__("from")},
                        {field: 'number',operate:false, title:__("number")},
                        {field: 'pay_time',operate:false, title:__("Otime")},
                        {field: 'pay_type', title: __('pay_type'),operate:false,searchList:{"0":__('pay_type0'),"1":__('pay_type1'),"2":__('pay_type2')},formatter:Table.api.formatter.normal},
                        {field: 'pay_statustext',operate:false, title:__("Pay_status")},
                        {field: 'refund_statustext',operate:false, title:__("Refund_status")},

                    ]
                ],
                pagination :false

            });



            // 为表格绑定事件
            Table.api.bindevent(table);
            table.on('post-body.bs.table',function () {

                $(".btn-editone").data("title", "修改订单的信息"); //自定义弹窗标题
                $(".btn-editone").data("area", ["80%","80%"]);//修改弹窗大小
            });


        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
            $(".btn-refresh").trigger('click');
            //parent.location.reload();//刷新这个页面

        },
        retprice: function () {//没新增一个弹窗页面 这里都要配置，否则 执行成功后 无法关闭弹窗
            Controller.api.bindevent();
            setTimeout(function () {
                $("#c-type").trigger("change");
            }, 100);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));

            }
        }
    };




    //申请退款
    $("#applyMoney").click(function () {
        var Oids = $("#c-orderIds").val();
        layer.confirm('是否确定申请退款?', {icon: 3, title:'申请退款'}, function(index){

            $.ajax({
                type: "POST",
                url: "order/applyMoney",
                data: {Oids:Oids},
                dataType: "json",
                success: function(data){
                    if(data.code == 1){
                        layer.msg(data.msg,{time:2000,icon: 6})
                        $("#applyMoney").attr("disabled","disabled");
                    }else{
                        layer.msg(data.msg,{time:2000,icon: 5})
                        return false;
                    }

                }
            });

            layer.close(index);
        });

    })


    //执行退款
    $("#doReturnMoney").click(function () {
        var Oids = $("#c-orderIds").val();
        layer.confirm('是否确定执行退款，操作不可回退?', {icon: 3, title:'执行退款'}, function(index){

            $.ajax({
                type: "POST",
                url: "order/doreturnprice",
                data: {Oids:Oids},
                dataType: "json",
                success: function(data){
                    if(data.code == 1){
                        layer.msg(data.msg,{time:2000,icon: 6})
                        $("#doReturnMoney").attr("disabled","disabled");
                    }else{
                        layer.msg(data.msg,{time:2000,icon: 5})
                        return false;
                    }

                }
            });

            layer.close(index);
        });

    })






    return Controller;
});
